//
//  OldPhotoAddAlertView.m

#import "OldPhotoAddAlertView.h"
#import "AppDelegate.h"
@interface OldPhotoAddAlertView()
@property (nonatomic,strong) zhPopupController *oldPhotoAddAlertViewPopUp;
@property (nonatomic,strong) UITextField *oldPhotoAddNameField;
@property (nonatomic,strong) UIButton * oldPhotoAddPaiXuShunBtn;
@property (nonatomic,strong) UIButton * oldPhotoAddPaiXuBackBtn;
@property (nonatomic, copy) void (^OldPhotoAddAlertBlock)(NSString *name,BOOL isFort);
@end
@implementation OldPhotoAddAlertView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = OldPhotoHex(@"#FFFFFF");
        self.layer.cornerRadius = OldPhotoRatio(20);
        self.clipsToBounds = true;
        [self creatSubView];
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(endEdit)];
        [self addGestureRecognizer:tapGesture];
    }
    return self;
}
- (void)creatSubView{
    UILabel * oldPhotoAddAlertHeadLab = [[UILabel alloc] init];
    oldPhotoAddAlertHeadLab.font = [UIFont systemFontOfSize:OldPhotoRatio(34) weight:UIFontWeightRegular];
    oldPhotoAddAlertHeadLab.textColor = OldPhotoHex(@"#222222");
    oldPhotoAddAlertHeadLab.text = @"添加美好瞬间";
    oldPhotoAddAlertHeadLab.textAlignment = NSTextAlignmentCenter;
    [self addSubview:oldPhotoAddAlertHeadLab];
    [oldPhotoAddAlertHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(OldPhotoRatio(0)));
        make.right.equalTo(@(-OldPhotoRatio(0)));
        make.top.equalTo(@(OldPhotoRatio(44)));
        make.height.equalTo(@(OldPhotoRatio(48)));
    }];
    UILabel * oldPhotoAddAlertTitleLab = [[UILabel alloc] init];
    oldPhotoAddAlertTitleLab.font = [UIFont systemFontOfSize:OldPhotoRatio(32) weight:UIFontWeightRegular];
    oldPhotoAddAlertTitleLab.textColor = OldPhotoHex(@"#222222");
    oldPhotoAddAlertTitleLab.text = @"记录瞬间";
    [self addSubview:oldPhotoAddAlertTitleLab];
    [oldPhotoAddAlertTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(OldPhotoRatio(40)));
        make.top.equalTo(oldPhotoAddAlertHeadLab.mas_bottom).offset(OldPhotoRatio(56));
        make.height.equalTo(@(OldPhotoRatio(45)));
    }];
    self.oldPhotoAddNameField = [[UITextField alloc] init];
    self.oldPhotoAddNameField.textColor = OldPhotoHex(@"#222222");
    self.oldPhotoAddNameField.backgroundColor = OldPhotoHex(@"#F8F8FB");
    self.oldPhotoAddNameField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, OldPhotoRatio(29), 0)];
    self.oldPhotoAddNameField.leftViewMode = UITextFieldViewModeAlways;
    self.oldPhotoAddNameField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入要记录的瞬间" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:OldPhotoRatio(32) weight:UIFontWeightRegular],NSForegroundColorAttributeName:OldPhotoHex(@"#ABABAD")}];
    self.oldPhotoAddNameField.font = [UIFont systemFontOfSize:OldPhotoRatio(32) weight:UIFontWeightRegular];
    self.oldPhotoAddNameField.layer.cornerRadius = OldPhotoRatio(16);
    self.oldPhotoAddNameField.clipsToBounds = true;
    [self addSubview:self.oldPhotoAddNameField];
    [self.oldPhotoAddNameField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(OldPhotoRatio(40)));
        make.right.equalTo(@(-OldPhotoRatio(40)));
        make.top.equalTo(oldPhotoAddAlertTitleLab.mas_bottom).offset(OldPhotoRatio(16));
        make.height.equalTo(@(OldPhotoRatio(98)));
    }];
    UILabel * oldPhotoAddPaiXuTitleLab = [[UILabel alloc] init];
    oldPhotoAddPaiXuTitleLab.font = [UIFont systemFontOfSize:OldPhotoRatio(32) weight:UIFontWeightRegular];
    oldPhotoAddPaiXuTitleLab.textColor = OldPhotoHex(@"#222222");
    oldPhotoAddPaiXuTitleLab.text = @"排序";
    [self addSubview:oldPhotoAddPaiXuTitleLab];
    [oldPhotoAddPaiXuTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(OldPhotoRatio(40)));
        make.top.equalTo(self.oldPhotoAddNameField.mas_bottom).offset(OldPhotoRatio(42));
        make.height.equalTo(@(OldPhotoRatio(45)));
    }];
    self.oldPhotoAddPaiXuShunBtn = [[UIButton alloc] init];
    [self.oldPhotoAddPaiXuShunBtn setTitle:@"置顶" forState:UIControlStateNormal];
    [self.oldPhotoAddPaiXuShunBtn setImage:OldPhotoImageNamed(@"OldPhotoUploadNoSelect") forState:UIControlStateNormal];
    [self.oldPhotoAddPaiXuShunBtn setImage:OldPhotoImageNamed(@"OldPhotoUploadSelect") forState:UIControlStateSelected];
    [self.oldPhotoAddPaiXuShunBtn setTitleColor:OldPhotoHex(@"#151B2F") forState:UIControlStateNormal];
    [self.oldPhotoAddPaiXuShunBtn setTitleColor:OldPhotoHex(@"#9B53F3") forState:UIControlStateSelected];
    self.oldPhotoAddPaiXuShunBtn.titleLabel.font = [UIFont systemFontOfSize:OldPhotoRatio(32) weight:UIFontWeightRegular];
    [self.oldPhotoAddPaiXuShunBtn addTarget:self action:@selector(oldPhotoAddPaiXuShun) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.oldPhotoAddPaiXuShunBtn];
    [self.oldPhotoAddPaiXuShunBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(OldPhotoRatio(40)));
        make.width.equalTo(@(OldPhotoRatio(108)));
        make.height.equalTo(@(OldPhotoRatio(34)));
        make.top.equalTo(oldPhotoAddPaiXuTitleLab.mas_bottom).offset(OldPhotoRatio(30));
    }];
    self.oldPhotoAddPaiXuBackBtn = [[UIButton alloc] init];
    [self.oldPhotoAddPaiXuBackBtn setTitle:@"置底" forState:UIControlStateNormal];
    [self.oldPhotoAddPaiXuBackBtn setImage:OldPhotoImageNamed(@"OldPhotoUploadNoSelect") forState:UIControlStateNormal];
    [self.oldPhotoAddPaiXuBackBtn setImage:OldPhotoImageNamed(@"OldPhotoUploadSelect") forState:UIControlStateSelected];
    [self.oldPhotoAddPaiXuBackBtn setTitleColor:OldPhotoHex(@"#151B2F") forState:UIControlStateNormal];
    [self.oldPhotoAddPaiXuBackBtn setTitleColor:OldPhotoHex(@"#9B53F3") forState:UIControlStateSelected];
    self.oldPhotoAddPaiXuBackBtn.titleLabel.font = [UIFont systemFontOfSize:OldPhotoRatio(32) weight:UIFontWeightRegular];
    [self.oldPhotoAddPaiXuBackBtn addTarget:self action:@selector(oldPhotoAddPaiXuBack) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.oldPhotoAddPaiXuBackBtn];
    [self.oldPhotoAddPaiXuBackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.oldPhotoAddPaiXuShunBtn.mas_right).offset(OldPhotoRatio(139));
        make.width.equalTo(@(OldPhotoRatio(108)));
        make.height.equalTo(@(OldPhotoRatio(34)));
        make.top.equalTo(self.oldPhotoAddPaiXuShunBtn);
    }];
    UIButton * oldPhotoAddSureBtn = [[UIButton alloc] init];
    [oldPhotoAddSureBtn setBackgroundImage:OldPhotoImageNamed(@"OldPhotoUploadBg") forState:UIControlStateNormal];
    [oldPhotoAddSureBtn addTarget:self action:@selector(oldPhotoAddSure) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:oldPhotoAddSureBtn];
    [oldPhotoAddSureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.equalTo(@(OldPhotoRatio(609)));
        make.height.equalTo(@(OldPhotoRatio(80)));
        make.bottom.equalTo(@(-OldPhotoRatio(49)));
    }];
    [self oldPhotoAddPaiXuShun];
}
- (void)endEdit{
    [self endEditing:false];
}
- (void)oldPhotoAddPaiXuShun{
    self.oldPhotoAddPaiXuShunBtn.selected = true;
    self.oldPhotoAddPaiXuBackBtn.selected = false;
}
- (void)oldPhotoAddPaiXuBack{
    self.oldPhotoAddPaiXuShunBtn.selected = false;
    self.oldPhotoAddPaiXuBackBtn.selected = true;
}
- (void)oldPhotoAddSure{
    if(self.oldPhotoAddNameField.text.length > 0){
        [_oldPhotoAddAlertViewPopUp dismiss];
        if(self.OldPhotoAddAlertBlock){
            self.OldPhotoAddAlertBlock(self.oldPhotoAddNameField.text, self.oldPhotoAddPaiXuShunBtn.isSelected);
        }
    }else{
        [SVProgressHUD showInfoWithStatus:@"请输入要记录的瞬间"];
    }
}
+ (void)showOldPhotoAddAlertView:(void(^)(NSString *name,BOOL isFort))complaint{
    OldPhotoAddAlertView *oldPhotoAddAlertView = [[OldPhotoAddAlertView alloc] init];
    zhPopupController *oldPhotoAddAlertViewPopUp = [[zhPopupController alloc] initWithView:oldPhotoAddAlertView size:CGSizeMake(OldPhotoRatio(690), OldPhotoRatio(705))];
    oldPhotoAddAlertView.OldPhotoAddAlertBlock = complaint;
    oldPhotoAddAlertView.oldPhotoAddAlertViewPopUp = oldPhotoAddAlertViewPopUp;
    oldPhotoAddAlertViewPopUp.presentationStyle = zhPopupSlideStyleTransform;
    oldPhotoAddAlertViewPopUp.layoutType = zhPopupLayoutTypeCenter;
    oldPhotoAddAlertViewPopUp.presentationTransformScale = 1.25;
    oldPhotoAddAlertViewPopUp.dismissonTransformScale = 0.85;
    oldPhotoAddAlertViewPopUp.maskAlpha = 0.6;
    oldPhotoAddAlertViewPopUp.dismissOnMaskTouched = false;
    [oldPhotoAddAlertViewPopUp showInView:((AppDelegate*)([UIApplication sharedApplication].delegate)).window completion:^{
      
    }];
}

@end
